package cn.zane.designPattern.createPatterns.factoryMethodPatterns.design;

import cn.zane.designPattern.createPatterns.factoryMethodPatterns.design.store.ICommodity;
import cn.zane.designPattern.createPatterns.factoryMethodPatterns.design.store.impl.CardCommodityService;
import cn.zane.designPattern.createPatterns.factoryMethodPatterns.design.store.impl.CouponCommodityService;
import cn.zane.designPattern.createPatterns.factoryMethodPatterns.design.store.impl.GoodsCommodityService;

/**
 * @Author: zane
 * @Date: 2024/12/25
 * @Description:
 */
public class StoreFactory {

    /**
     * 奖品类型方式实例化
     *
     * @param commodityType 奖品类型
     * @return 实例化对象
     */
    public ICommodity getCommodityService(Integer commodityType) {
        if (null == commodityType) return null;
        if (1 == commodityType) {
            return new CouponCommodityService();
        }
        if (2 == commodityType) {
            return new GoodsCommodityService();
        }
        if (3 == commodityType) {
            return new CardCommodityService();
        }
        throw new RuntimeException("不存在的奖品服务类型");
    }

    /**
     * 奖品类信息方式实例化
     *
     * @param clazz 奖品类
     * @return 实例化对象
     */
    public ICommodity getCommodityService(Class<? extends ICommodity> clazz) throws InstantiationException, IllegalAccessException {
        if (null == clazz) return null;
        return clazz.newInstance();
    }
}
